//
//  ActivityCenterView.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/6/6.
//

#import "ActivityCenterView.h"
#import "CommonUtil.h"
#import "BtnView.h"
#import "ReceiveRuleView.h"
@interface ActivityCenterView()
@property (strong, nonatomic) UIView * bgView;
@property (strong, nonatomic) UIView * whiteView;
@property (strong, nonatomic) BtnView * btn1;
@property (strong, nonatomic) BtnView * btn2;
@property (strong, nonatomic) BtnView * btn3;
@property (strong, nonatomic) BtnView * btn4;

@property (strong, nonatomic) UIView * line1;
@property (strong, nonatomic) UIView * line2;
@property (strong, nonatomic) UIView * line3;

@property (strong, nonatomic) UILabel * tip1;
@property (strong, nonatomic) UILabel * tip2;

@property (strong, nonatomic) UIImageView * currentLevelImageView;
@property (strong, nonatomic) UIImageView * nextLevelImageView;
@property (strong, nonatomic) UIImageView * xinshoushangluImageView;
@property (strong, nonatomic) UIImageView * liuheyiminImageView;

@property (strong, nonatomic) UILabel * valueLabel;

@property (strong, nonatomic) UIView * indexBGView;
@property (strong, nonatomic) UIView * indexView;

@property (strong, nonatomic) UIScrollView * contentScrView;

@property (strong, nonatomic) ReceiveRuleView * ruleView;

@property (strong, nonatomic) UIView * tabView;
@property (strong, nonatomic) UIButton * selectBtn;
@property (strong, nonatomic) UIView * tipView;
@end

@implementation ActivityCenterView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.bgView];
        [self addSubview:self.whiteView];
        [self.whiteView addSubview:self.btn1];
        [self.whiteView addSubview:self.btn2];
        [self.whiteView addSubview:self.btn3];
        [self.whiteView addSubview:self.btn4];
        
        [self.whiteView addSubview:self.line1];
        [self.whiteView addSubview:self.line2];
        [self.whiteView addSubview:self.line3];
        
        [self.whiteView addSubview:self.tip1];
        [self.whiteView addSubview:self.tip2];
        
        [self.whiteView addSubview:self.currentLevelImageView];
        [self.whiteView addSubview:self.nextLevelImageView];
        [self.whiteView addSubview:self.xinshoushangluImageView];
        [self.whiteView addSubview:self.liuheyiminImageView];
        
        [self.whiteView addSubview:self.valueLabel];
        [self.whiteView addSubview:self.indexBGView];
        [self.indexBGView addSubview:self.indexView];
        
        [self addSubview:self.contentScrView];
        [self addSubview:self.ruleView];
        
        [self addSubview:self.tabView];
        [self addSubview:self.tipView];
        
        
        self.height = self.tipView.bottom;
    }
    return self;
}


-(void)setModel:(ActivityModel *)model{
    _model = model;
    self.indexView.width = self.indexBGView.width * 0.28;
    CGFloat margin = AD(10);
    CGFloat w = AD(350);
    for (NSInteger i = 0; i < 3; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.tag = i;
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.frame = CGRectMake(i * (w + margin), 0, w, self.contentScrView.height);
        [btn setBackgroundImage:[UIImage imageNamed:@"forum_bg.jpg"] forState:UIControlStateNormal];
        [self.contentScrView addSubview:btn];
        self.contentScrView.contentSize = CGSizeMake(btn.right, 0);
        btn.layer.cornerRadius = AD(5);
        btn.clipsToBounds = YES;
    }
    
}

- (void)btnClick:(UIButton *)sender{
    NSLog(@"活动页%zd",sender.tag);
}

- (void)choujiangbtnClick:(UIButton *)sender{
    NSLog(@"抽奖");
}

- (void)tabbtnClick:(UIButton *)sender{
    self.selectBtn.selected = false;
    self.selectBtn.backgroundColor = [UIColor clearColor];
    self.selectBtn.layer.cornerRadius = AD(0);
    self.selectBtn = sender;
    self.selectBtn.selected = YES;
    self.selectBtn.backgroundColor = [UIColor whiteColor];
    self.selectBtn.layer.cornerRadius = AD(5);
    
    if (self.actionBlock) {
        self.actionBlock(sender.tag);
    }
    
}

-(UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, -self.width*1.2, self.width*1.5, self.width*1.5)];
        _bgView.layer.cornerRadius = _bgView.width/2;
        _bgView.backgroundColor = RGB(255, 90, 117);
        _bgView.centerX = self.width/2;
    }
    return _bgView;
}


-(UIView *)whiteView{
    if (!_whiteView) {
        _whiteView = [[UIView alloc] initWithFrame:CGRectMake(AD(15), 0, self.width-AD(30), AD(185))];
        _whiteView.layer.cornerRadius = AD(5);
        _whiteView.backgroundColor = [UIColor whiteColor];
    }
    return _whiteView;
}

-(BtnView *)btn1{
    if (!_btn1) {
        CGFloat w = self.whiteView.width/4;
        _btn1 = [[BtnView alloc] initWithFrame:CGRectMake(0, AD(5), w, AD(40))];
        _btn1.label1.text = @"43";
        _btn1.label2.text = @"进行中";
    }
    return _btn1;
}

-(BtnView *)btn2{
    if (!_btn2) {
        CGFloat w = self.whiteView.width/4;
        _btn2 = [[BtnView alloc] initWithFrame:CGRectMake(self.btn1.right, self.btn1.top, w, AD(40))];
        _btn2.label1.text = @"2";
        _btn2.label2.text = @"未领取";
    }
    return _btn2;
}
-(BtnView *)btn3{
    if (!_btn3) {
        CGFloat w = self.whiteView.width/4;
        _btn3 = [[BtnView alloc] initWithFrame:CGRectMake(self.btn2.right, self.btn1.top, w, AD(40))];
        _btn3.label1.text = @"2.61";
        _btn3.label2.text = @"我的彩金";
    }
    return _btn3;
}
-(BtnView *)btn4{
    if (!_btn4) {
        CGFloat w = self.whiteView.width/4;
        _btn4 = [[BtnView alloc] initWithFrame:CGRectMake(self.btn3.right, self.btn1.top, w, AD(40))];
        _btn4.label1.text = @"12";
        _btn4.label2.text = @"小红花";
    }
    return _btn4;
}


-(UIView *)line1{
    if (!_line1) {
        _line1 = [[UIView alloc] initWithFrame:CGRectMake(self.btn1.right, AD(5), AD(1), AD(30))];
        _line1.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    }
    return _line1;
}

-(UIView *)line2{
    if (!_line2) {
        _line2 = [[UIView alloc] initWithFrame:CGRectMake(self.btn2.right, AD(5), AD(1), AD(30))];
        _line2.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    }
    return _line2;
}


-(UIView *)line3{
    if (!_line3) {
        _line3 = [[UIView alloc] initWithFrame:CGRectMake(self.btn2.right, AD(5), AD(1), AD(30))];
        _line3.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    }
    return _line3;
}


-(UILabel *)tip1{
    if (!_tip1) {
        _tip1 = [[UILabel alloc] initWithFrame:CGRectMake(AD(10), _btn1.bottom + AD(20), AD(130), AD(25))];
        _tip1.text = @"距离下一级还差:";
        _tip1.textColor = [UIColor blackColor];
        _tip1.font = [UIFont systemFontOfSize:AD(16)];
    }
    return _tip1;
}

-(UILabel *)tip2{
    if (!_tip2) {
        _tip2 = [[UILabel alloc] initWithFrame:CGRectMake(_tip1.right + AD(5), _btn1.bottom + AD(20), AD(120), AD(25))];
        _tip2.text = @"39成长值";
        _tip2.textColor = RGB(252, 94, 71);
        _tip2.font = [UIFont systemFontOfSize:AD(19)];
    }
    return _tip2;
}

-(UIImageView *)currentLevelImageView{
    if (!_currentLevelImageView) {
        _currentLevelImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_currentlevel"]];
        _currentLevelImageView.frame = CGRectMake(AD(10), _tip1.bottom + AD(20), AD(50), AD(20));
    }
    return _currentLevelImageView;
}

-(UIImageView *)nextLevelImageView{
    if (!_nextLevelImageView) {
        _nextLevelImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_nextlevel"]];
        _nextLevelImageView.frame = CGRectMake(0, _currentLevelImageView.top, AD(50), AD(20));
        _nextLevelImageView.right = self.whiteView.width - AD(10);
    }
    return _nextLevelImageView;
}

-(UIImageView *)xinshoushangluImageView{
    if (!_xinshoushangluImageView) {
        _xinshoushangluImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_xinshoushanglu"]];
        _xinshoushangluImageView.frame = CGRectMake(AD(10), _currentLevelImageView.bottom + AD(10), AD(70), AD(20));
    }
    return _xinshoushangluImageView;
}

-(UIImageView *)liuheyiminImageView{
    if (!_liuheyiminImageView) {
        _liuheyiminImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_liuheyimin"]];
        _liuheyiminImageView.frame = CGRectMake(0, _currentLevelImageView.bottom + AD(10), AD(70), AD(20));
        _liuheyiminImageView.right = self.whiteView.width - AD(10);
    }
    return _liuheyiminImageView;
}

-(UILabel *)valueLabel{
    if (!_valueLabel) {
        _valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _currentLevelImageView.bottom-AD(5), self.whiteView.width, AD(20))];
        _valueLabel.text = @"成长值:11";
        _valueLabel.textColor = RGB(181, 181, 181);
        _valueLabel.font = [UIFont systemFontOfSize:AD(13)];
        _valueLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _valueLabel;
}
-(UIView *)indexBGView{
    if (!_indexBGView) {
        _indexBGView = [[UIView alloc] initWithFrame:CGRectMake(self.xinshoushangluImageView.right + AD(5), AD(5), AD(150), AD(10))];
        _indexBGView.backgroundColor = RGB(225, 225, 225);
        _indexBGView.centerX = self.whiteView.width/2;
        _indexBGView.centerY = self.xinshoushangluImageView.centerY;
        _indexBGView.layer.cornerRadius = AD(5);
        _indexBGView.clipsToBounds = YES;
    }
    return _indexBGView;
}


-(UIView *)indexView{
    if (!_indexView) {
        _indexView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, self.indexBGView.height)];
        _indexView.backgroundColor = RGB(255,76, 47);
        _indexView.layer.cornerRadius = AD(5);
    }
    return _indexView;
}

-(UIScrollView *)contentScrView{
    if (!_contentScrView) {
        CGFloat w = SCREEN_WIDTH-AD(30);
        _contentScrView = [[UIScrollView alloc] initWithFrame:CGRectMake(AD(15), self.whiteView.bottom + AD(15),w, AD(180))];
        _contentScrView.layer.cornerRadius = AD(5);
        _contentScrView.clipsToBounds = YES;
        _contentScrView.userInteractionEnabled = YES;
    }
    return _contentScrView;
}

-(ReceiveRuleView *)ruleView{
    if (!_ruleView) {
        _ruleView = [[ReceiveRuleView alloc] initWithFrame:CGRectMake(AD(15), self.contentScrView.bottom + AD(10), SCREEN_WIDTH-AD(30), AD(150))];
    }
    return _ruleView;
}


-(UIView *)tabView{
    if (!_tabView) {
        _tabView = [[UIView alloc] initWithFrame:CGRectMake(AD(15),_ruleView.bottom + AD(10), self.width - AD(30), AD(80))];
        _tabView.backgroundColor = RGB(255, 90, 117);
        _tabView.layer.cornerRadius = AD(10);
        _tabView.clipsToBounds = YES;
        NSArray *titles = @[@"今日任务",@"日常活动",@"勋章活动"];
        CGFloat w = _tabView.width/3;
        for (NSInteger i = 0; i < 3; i++) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn addTarget:self action:@selector(tabbtnClick:) forControlEvents:UIControlEventTouchUpInside];
            [btn setTitle:titles[i] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
            btn.titleLabel.font = [UIFont boldSystemFontOfSize:AD(18)];
            [_tabView addSubview:btn];
            btn.tag = i;
            btn.frame = CGRectMake(i * w, 0, w, AD(60));
            if (i == 0) {
                [self tabbtnClick:btn];
            }
            
            if (i < 2) {
                UIView *v = [[UIView alloc] initWithFrame:CGRectMake(btn.right-AD(1), AD(20), AD(1), AD(20))];
                v.backgroundColor = [UIColor whiteColor];
                [_tabView addSubview:v];
            }
            
        }
        
    }
    return _tabView;
}
-(UIView *)tipView{
    if (!_tipView) {
        _tipView = [[UIView alloc] initWithFrame:CGRectMake(AD(15), _tabView.bottom - AD(25), self.width-AD(30), AD(45))];
        _tipView.backgroundColor = [UIColor whiteColor];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(AD(10), AD(5), _tipView.width-AD(20), AD(35))];
        label.layer.cornerRadius = label.height/2;
        label.backgroundColor = RGB(240, 240, 240);
        label.textColor = RGB(155, 155, 155);
        label.clipsToBounds = YES;
        label.font = [UIFont systemFontOfSize:AD(14)];
        label.text = @"  完成5个任务可以开启一次抽奖机会";
        [_tipView addSubview:label];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_tipView addSubview:btn];
        btn.backgroundColor = RGB(161, 161, 161);
        [btn setTitle:@"去抽奖" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:AD(15)];
        [btn addTarget:self action:@selector(choujiangbtnClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.frame = CGRectMake(0, AD(10), AD(60), AD(25));
        btn.layer.cornerRadius = btn.height/2;
        btn.right = _tipView.width - AD(10);
        
    }
    return _tipView;
}


@end
